package mygang.dao.simple;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import mygang.model.Option;
import org.apache.log4j.Logger;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 * date: 09/01/2013
 */
public class TestDAO extends BaseDAO {

    private static final Logger log = Logger.getLogger(TestDAO.class.toString());

    public TestDAO(){}
    
    public static void main(String[] args) {
        log.debug(getTablesList().toString());
    }
    
    
    public static List<Option> getTablesList(){
        ResultSet rs = null;
        PreparedStatement ps = null;
        List<Option> result = new ArrayList<Option>();
        try {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT TABLE_NAME ");
            sb.append("FROM INFORMATION_SCHEMA.TABLES ");
            sb.append("WHERE TABLE_SCHEMA = ?");
  
            open();
            ps = conn.prepareStatement(sb.toString());
            ps.setString(1, getProperty(NAME));
            rs = ps.executeQuery();
            
            while(rs.next()){
                String table = rs.getString(1).toUpperCase();
                Option option = new Option(table, table);
                result.add(option);
            }
            
        } catch (SQLException ex) {
            log.error(ex.getMessage());
        } finally {
            try {
                ps.close();
                rs.close();
                close();
            } catch (SQLException ex) {
                log.error(ex.getMessage());
            }
        }
        return result;
    }

}